#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <string.h>
#include <unistd.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <stdlib.h>
#include <pthread.h>
#include "cJSON.h"
#include "shmem.h"
#include "msg_queue_peer.h"
#include <semaphore.h>

#define MAX_NODE 128  //最大支持节点数目，实际可用是127
#define STD_NODE_LEN sizeof(stm_node_t)
#define MAX_NODE_SIZE (MAX_NODE * STD_NODE_LEN)
#define _PATH "/home/hq/c/config/project.json"
#define _PORT 8886

typedef union val
{ 
    int b_val;  //bool类型存储空间
    int i_val;   //整形值存储空间
    float f_val;  //浮点值存储空间
} val_t;

typedef struct stm_node
{
	int key;  //唯一键值
	int type;  //数据点类型
    int dev_type;  //数据点属于哪个设备，根据网关支持的设备自行定义
	val_t old_val;  //变化上报后需要更新旧值
    val_t new_val;  //从共享内存取出最新数据，放到new_val中
    int ret;  //默认为-1，采集成功后设置为0，采集失败再置-1
}stm_node_t, *stm_node_p;

typedef struct key_t
{
    int key; 
    char name[16];
    int type;
} key_ch, *key_p;

typedef struct msgbuf
{
    long mtype;
    int mkey;
    char value[16];
    int addr;
}msgbuf_t, *msgbuf_p;

enum
{
    TYPE_INT = 1,
    TYPE_BOOL,
    TYPE_FLOAT
};